package com.tmt.asm;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class JdkProxy implements InvocationHandler {

	// 目标对象
	private Object target;
	private Class<?> type;
	
	public JdkProxy(Class<?> type, Object target) {
		this.target = target;
		this.type = type;
	}
	
	public Object getProxy() {
		return Proxy.newProxyInstance(this.type.getClassLoader(), 
				new Class[] { this.type },
				this);
	}

	@Override
	public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
		return method.invoke(target, args);
	}
}